<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title>个人中心</title>
		<link href="../css/mui.min.css" rel="stylesheet" />
		<link href="../css/style.css" rel="stylesheet" />
		<link rel="stylesheet" href="../fonts/iconfont.css" />
		<style>
			.mui-page .mui-table-view:first-child {margin-top: 15px;}
			.mui-page .mui-table-view:last-child {margin-bottom: 30px;}
			.mui-table-view {margin-top: 10px;}
			.table-view-combine:after {height: 0;}
			.mui-table-view span.mui-pull-right {color: #999;}
			.mui-grid-view.mui-grid-9{ background-color: #fff; margin: 0;}
			.mui-grid-view.mui-grid-9:after{ position: absolute; display: block;}
			.mui-grid-view.mui-grid-9 .mui-table-view-cell{padding: 0; border: 0;}
			.mui-grid-view.mui-grid-9 .mui-table-view-cell .mui-badge,.mui-table-view-chevron .mui-badge{ display: none;}
			.mui-grid-view.mui-grid-9 .mui-media .mui-icon{font-size:24px; color: #666;-webkit-text-stroke-width: 0.3px;}
			.mui-table-view.mui-grid-view .mui-table-view-cell .mui-media-body{ font-size: 12px;}
			.mui-media.mui-col-xs-3{ width: 20%;}
			.mui-table-view .iconfont{ font-size: 20px;-webkit-text-stroke-width: 0.3px;}
			.table-view-iconlist .iconfont{margin-right: 5px;}
			.icon-top .iconfont{ position: relative; top: 2px;}
			.user-info{ position: relative;padding: 1px 0 12px; color: #fff; text-align: center; margin-top: -1px; height: 160px;background:url(../images/userImg.png) no-repeat;background-size: 100% 100%;}
			.user-info img{ height: 70px; display:inline; border-radius: 100%;}
			.user-info .set{color: #f0ad4e;font-size: 30px;position: absolute;right:2%;top: 5%;}
			.user-info ul li:first-child{ padding: 0 20% 0 5%; position: relative; }
			.user-info ul li:first-child:after{content: '';position: absolute; right: 0; height: 20px;border-left: 1px solid #fff; bottom: 0;}
			.user-info ul li strong{font-size: 22px; font-weight: normal;}
			.user-info ul li p{ color: #fff; margin: 0;}
			.scroll-div{ top: 161px;}
		</style>
	</head>  
    
	<body>
		<div class="mui-content">
			<div class="user-info" id="userBg"> 
				<!--<i class="iconfont icon-shezhi set" id="set" ></i>-->
			</div>
			<div id="scrollDiv" class="scroll-div">
				
				<!--<ul class="mui-table-view mui-table-view-chevron table-view-iconlist">
					<li class="mui-table-view-cell">
						<a id="userCoupon" class="mui-navigate-right"> 
							
							<span class="mui-icon iconfont icon-youhuiquan"></span>
							<span class="mui-badge mui-badge-danger" id="Counpon"></span>我的优惠券
						</a>
					</li>
					<li class="mui-table-view-cell">
							<span class="mui-icon iconfont icon-jifen"></span>我的积分
							<span class="mui-badge mui-badge-inverted" id="Integral" style="display: inline-block;"></span>
					</li>
					<li class="mui-table-view-cell">
						<a id="myHistory" class="mui-navigate-right">
							<span class="mui-icon iconfont icon-zuji"></span>我的足迹
						</a>
					</li>
					<li class="mui-table-view-cell">
                        <a id="myMerge" class="mui-navigate-right">
                            <span class="mui-icon iconfont icon-pintuan"></span>
                            <span class="mui-badge mui-badge-inverted" id="myMergeTip" style="display: inline-block;"></span>我的拼团
                        </a>
                   </li>
				</ul>-->
				<ul class="mui-table-view mui-table-view-chevron table-view-iconlist icon-top">
					<li class="mui-table-view-cell">
						<a id="showInvite" class="mui-navigate-right"><span class="mui-icon iconfont icon-yaoqing"></span>申请加入企业</a>
					</li>
					<li class="mui-table-view-cell">
						<a id="addCompany" class="mui-navigate-right"><span class="mui-icon iconfont icon-pintuan"></span>申请成为企业</a>
					</li>
					<li class="mui-table-view-cell">
						<a id="myQR" class="mui-navigate-right"><span class="mui-icon iconfont icon-address"></span>我的二维码</a>
					</li>
					
					
				</ul>
				<ul class="mui-table-view mui-table-view-chevron table-view-iconlist icon-top">
					<!--<li class="mui-table-view-cell">
						<a id="set" class="mui-navigate-right"><span class="mui-icon iconfont icon-account"></span>修改个人资料</a>
					</li>-->
					<li class="mui-table-view-cell">
						<a id="accountManagement" class="mui-navigate-right"><span class="mui-icon iconfont icon-account"></span>修改密码</a>
					</li>
				</ul> 
				<ul class="mui-table-view exit-box" style="margin-bottom: 20px; display: none;">
					<li class="mui-table-view-cell" style="text-align: center;">
						<a id='exit'>退出</a>
					</li>
				</ul>
				<a style="margin: 15px;" id='login' class="custom-btn">登录</a>
			</div>
		</div>
		<script src="../js/mui.min.js"></script>
		<script src="../js/app.js"></script>
		<script src="../js/mui.previewimage.js"></script>
		<script>
			var state={},
				userId,
				auths=null,
				CellPhone;
//			var account = document.getElementById('account');
			var loginbtn=document.getElementById('login');
			var userBg=document.getElementById('userBg');
			(function($, doc) {
				$.init();
				$.plusReady(function() {
					if(!himall.isLogin()){
											
						loginbtn.addEventListener('tap',function(){
							window.scrollTo(0,0);
							showLogin({},'/');
						});
					}
					if(himall.isLogin()){
						console.log('商城个人中心2');
						getUserData();
					}
					
					
					
					doc.getElementById('myQR').addEventListener('tap',function(){
//						if(himall.isLogin()){
//							himall.openVW('myQR.html');
//						}else{
//							showLogin({id:'address.html',url:'user/address.html'},'/');
//						}
						himall.openVW('my-QR.html');
					});
					
//					doc.getElementById('showFavProduct').addEventListener('tap',function(){
//						if(himall.isLogin()){
//							himall.openVW('user-favproduct.html');
//						}else{
//							showLogin({id:'user-favproduct.html',url:'user/user-favproduct.html'},'/');
//						}
//					});
//					doc.getElementById('showFavShop').addEventListener('tap',function(){
//						if(himall.isLogin()){
//							himall.openVW('user-favshop.html');
//						}else{
//							showLogin({id:'user-favshop.html',url:'user/user-favshop.html'},'/');
//						}
//					});
					doc.getElementById('showInvite').addEventListener('tap',function(e){						
						e.detail.gesture.preventDefault(); //修复iOS 8.x平台存在的bug，使用plus.nativeUI.prompt会造成输入法闪一下又没了
						var btnArray = ['取消', '确定'];
						mui.prompt('请输入申请的企业ID：', '如111', '申请', btnArray, function(e) {
							if (e.index == 1) {
								plus.nativeUI.toast('申请已提交：' + e.value);
								//申请企业会员接口 预留
							} else {
								
							}
						})			
					});
					doc.getElementById('addCompany').addEventListener('tap',function(e){						
						himall.openVW('add-company.html');			
					});
//					doc.getElementById('accountManagement').addEventListener('tap',function(){
//						if(himall.isLogin()){
//							himall.openVW('user-account.html','',{CellPhone:CellPhone});
//						}else{
//							showLogin({id:'user-account.html',url:'user/user-account.html',extras:{CellPhone:CellPhone}},'/');
//						}
//					});
//					doc.getElementById('aboutUs').addEventListener('tap',function(){
//						himall.openVW('aboutus.html');
//					});
//					doc.getElementById('refundList').addEventListener('tap',function(){
//						if(himall.isLogin()){
//							himall.openVW('order-refund-list.html','../order-refund-list.html');
//						}else{
//							showLogin({id:'order-refund-list.html'},'/');
//						}
//					});
//					doc.getElementById('myMerge').addEventListener('tap', function(){
//					    if (himall.isLogin()) {
//					    	if(this.value==0){
//					    		himall.openVW('merge-any.html', '../marketing/merge-any.html');
//					    	}else{
//					    		himall.openVW('merge-personal-list.html', '../marketing/merge-personal-list.html');
//					    	}
//					    } else {
//					        showLogin({id:'merge-personal-list.html', url:'marketing/merge-personal-list.html'}, '/');
//					    }
//					})
					//账号管理
					doc.getElementById('accountManagement').addEventListener('tap',function(){
						if(himall.isLogin()){
							himall.openVW('../user/change-password.html','',{CellPhone:CellPhone});
						}else{
							showLogin({id:'change-password.html',url:'./user/change-password.html',extras:{CellPhone:CellPhone}},'/');
						}
					});
					//个人设置
//					doc.getElementById('set').addEventListener('tap',function(e){	 
//						himall.openVW('my-set.html');
//						e.stopPropagation();
//					});
					//背景图片
					doc.getElementById('userBg').addEventListener('tap',function(){
						 
						mui.openWindow({
							url:'userCard.html',
    						id:'userCard.html',
    						show:{
						      autoShow:true,//页面loaded事件发生后自动显示，默认为true
						      aniShow:'pop-in',//页面显示动画，默认为”slide-in-right“；
						      duration:100//页面动画持续时间，Android平台默认100毫秒，iOS平台默认200毫秒；
						    },
						    waiting: {
								autoShow: false
							}
						})
					});
				}); 
			}(mui, document));
			
			document.addEventListener('updateData', function() {
				if(himall.isLogin()){
					getUserData();
					console.log("出发")
				}
				
				document.getElementById('scrollDiv').scrollTop=0;
			});
			loginbtn.addEventListener('tap',function(){
				window.scrollTo(0,0);
				showLogin({},'/','myCenter/index');
			});
			function getUserData(){
				state = himall.getState();
				
				document.getElementById('login').style.display='none';
				document.getElementsByClassName('exit-box')[0].style.display='block';
				userId=state.userId;
				mui.ajax(URL+'api/UserCenter/GetUser/'+userId,{
					dataType:'json',
					type:'get',
					timeout:10000,
					success:function(data){
						if(data.Success=='true'){
							CellPhone=data.CellPhone;
							document.getElementById('FavoriteProduct').innerText=data.FavoriteProduct;
							document.getElementById('FavoriteShop').innerText=data.FavoriteShop;
							himall.whichShow(data.WaitingForPay,'WaitingForPay');
							himall.whichShow(data.WaitingForComments,'WaitingForComments');
							himall.whichShow(data.WaitingForRecieve,'WaitingForRecieve');
							himall.whichShow(data.WaitingForDelivery,'WaitingForDelivery');
							himall.whichShow(data.RefundOrders,'RefundOrders');
							himall.whichShow(data.Counpon,'Counpon');
							document.getElementById('Integral').innerText=data.Integral+'分';
							document.getElementById('myMerge').value=data.GroupTotal;
							if(data.MyGroup>0){
								document.getElementById('myMergeTip').innerText = data.MyGroup + '个团正在火拼中';
							}
							var userPhoto=data.Photo;
							if(userPhoto=='')
								userPhoto='../images/default-photo.png';
							else
								document.getElementById('userPhoto').src=userPhoto;
						}
					}
				});
			}
			
			function showOrderList(id){
				if(himall.isLogin()){
					himall.openVW('order-list.html','../order-list.html',{orderStatus:id});
				}else{
					showLogin({id:'order-list.html',extras:{orderStatus:id}},'/');
				}
			}
			
			//退出操作
			function backUser(){
				mui.ajax(URL+'api/Login/PostLogout',{
					dataType:'json',
					contentType:'application/json',
					type:'POST',
					timeout:10000,
					success:function(data){
						if(data.Success=="true"){
							console.log('退出接口');
							/*for ( var i in auths ) {
								var s = auths[i];
								if ( s.authResult ) {
									s.logout(function(e){
										plus.nativeUI.toast( "注销登录成功！" );
									}, function(e){
										plus.nativeUI.toast( "注销登录失败！" );
									});
								}
							}*/
							himall.setState({});
							plus.webview.currentWebview().reload();
						}
					},
					error:function(xhr,type,errorThrown){
						plus.nativeUI.toast('退出登录失败，请检查网络')
					}
				});
			}
			
			document.getElementById('exit').addEventListener('tap', function() {
				if (mui.os.ios) {
					backUser();
					return;
				}
				var btnArray = [{
					title: "注销当前账号"
				}, {
					title: "直接关闭应用"
				}];
				plus.nativeUI.actionSheet({
					cancel: "取消",
					buttons: btnArray
				}, function(event) {
					var index = event.index;
					switch (index) {
						case 1:
							backUser();
							break;
						case 2:
							plus.runtime.quit();
							break;
					}
				});
			}, false);
			
		</script>
	</body>

</html>